<template>
	<view class="count">
		<view class="white u-p-30">
			<text>请选择您想反馈的问题点</text>
			<u-radio-group v-model="value" size="50" @change="radioGroupChange" :wrap=true>
				<u-radio @change="radioChange" class="u-m-t-30" v-for="(item, index) in list" :key="index"
					:name="item.name" :disabled="item.disabled">
					<view class="u-m-l-30 u-font-35">
						{{item.name}}
					</view>
				</u-radio>
			</u-radio-group>
		</view>
		<view class="white u-p-40">
			<view class="u-m-b-20 u-flex">
				<text class="u-flex-1">请补充详细问题和意见</text>
				<view class="u-flex u-row-right">
					{{fontnum}}/200
				</view>
			</view>
			<textarea maxlength="200" placeholder="请补充详细问题和意见" @input="sumfontnum"></textarea>
		</view>
		<view class="white u-p-30">
			<view class="">
				请提供相关问题的图片
			</view>
			<view class="u-m-t-20">
				<u-upload :fileList="fileList6" @afterRead="afterRead" @delete="deletePic" name="6" multiple></u-upload>
			</view>
		</view>
		<view class="u-m-60">
			<u-button ripple shape="circle" type="primary">确定</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fontnum: 0,
				list: [{
						name: '功能异常：功能故障或不可用',
						disabled: false
					},
					{
						name: '产品建议：用的不爽，我有建议',
						disabled: false
					},
					{
						name: '其他问题',
						disabled: false
					}
				],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				value: '功能异常：功能故障或不可用',
				text: "",
				// 演示地址，请勿直接使用 
				action: '',
				fileList6: []
			};
		},
		onLoad(data) {
			console.log(data);
		},
		methods: {
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				// console.log(e);
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				// console.log(e);
			},
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].thumb)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			sumfontnum(e) {
				// console.log(e);
				this.fontnum = e.detail.value.length;
			}
		}
	};
</script>

<style lang="scss" scoped>
	.count {
		background-color: #f5f5f5;
		height: calc(100vh - 44px);
	}

	.white {
		margin: 20rpx auto;
		background-color: #FFFFFF;
	}
</style>
